author = "Peter J Usherwood"

Sample use case for transforming a standard coded taxanomy into a bycat form


In [1]:
import pandas as pd
import numpy as np
import csv
from main.tools.create_df import DF
from main.taxanomy.bycat import domains_to_binary, encoded_to_bycat_counts, bycat_counts_to_bycat_scores

In [9]:
df = DF([{'type': 'Binary', 'name': 'Tax', 'n_itters': 3, 'args': {'perc_ones':.45}},
         {'type': 'Binary', 'name': 'Cross Moment', 'n_itters': 3, 'args': {'perc_ones':.45}},
         {'type': 'Binary', 'name': 'Cross Brand', 'n_itters': 3, 'args': {'perc_ones':.45}},
         {'type': 'Number', 'name': 'Cross Sentiment', 'n_itters': 1, 'args': {}}], 
         n_records=10)

In [10]:
df


Out[10]:
Tax0 Tax1 Tax2 Cross Moment0 Cross Moment1 Cross Moment2 Cross Brand0 Cross Brand1 Cross Brand2 Cross Sentiment0
0 0.0 1.0 0.0 1.0 1.0 1.0 0.0 1.0 1.0 21.700967
1 1.0 0.0 0.0 0.0 1.0 1.0 1.0 0.0 1.0 40.172260
2 1.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 57.916953
3 0.0 0.0 1.0 1.0 1.0 0.0 0.0 0.0 1.0 80.511600
4 1.0 0.0 0.0 0.0 0.0 0.0 1.0 1.0 1.0 10.107857
5 1.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 1.0 26.340383
6 1.0 0.0 0.0 1.0 0.0 1.0 0.0 0.0 1.0 52.873498
7 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 1.0 29.783419
8 1.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 76.859239
9 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 60.176651

In [11]:
bycat = encoded_to_bycat_counts(df_encoded=df, tax_col_indicator='Tax', cross_col_indicator='Cross')
bycat


Out[11]:
Volume Cross Moment0 Cross Moment1 Cross Moment2 Cross Brand0 Cross Brand1 Cross Brand2 Cross Sentiment0
Tax0 6.0 2.0 1.0 2.0 3.0 1.0 4.0 264.270191
Tax1 1.0 1.0 1.0 1.0 0.0 1.0 1.0 21.700967
Tax2 3.0 1.0 1.0 0.0 0.0 1.0 2.0 167.028634

In [ ]: